<?php
//filename : m_stug.php

require_once APPPATH.'models/gnc_db_mysql'.EXT;

class M_STUG extends Gnc_db_mysql {
	protected $data_source	= 'stu_h_st';
	//agar saat data diedit, status tidak ditampilkan
	public function get_single($record) {
	
	    $myquery = "select id,id_request,no_st,d_st, pjb_ttd_st, kategori_tugas, perihal_tugas,lokasi_tugas,dt_berangkat,dt_kembali,transportasi,allowance from stu_h_st";  
		if (!is_array($record)) {
			$record = array('id' => NULL);
		}
		//bagian yang dioverride
		$metadata = $this->get_metadata($myquery);
		
		$data['n_all_records'] = $this->db->count_all($this->data_source);
		$data['first'] = current($this->db->query('SELECT id,id_request,no_st,d_st, pjb_ttd_st, kategori_tugas, perihal_tugas,lokasi_tugas,dt_berangkat,dt_kembali,transportasi,allowance FROM '.$this->data_source.' ORDER BY `'.key($record).'` ASC LIMIT 1')->result_array());
		$data['previous'] = current($this->db->query('SELECT id,id_request,no_st,d_st, pjb_ttd_st, kategori_tugas, perihal_tugas,lokasi_tugas,dt_berangkat,dt_kembali,transportasi,allowance FROM '.$this->data_source.' WHERE `'.key($record).'` < '.$this->db->escape(current($record)).' ORDER BY `'.key($record).'` DESC LIMIT 1')->result_array());
		$data['current'] = current($this->db->query('SELECT id,id_request,no_st,d_st, pjb_ttd_st, kategori_tugas, perihal_tugas,lokasi_tugas,dt_berangkat,dt_kembali,transportasi,allowance FROM '.$this->data_source.' WHERE '.$this->compile_where($record))->result_array());
		$data['next'] = current($this->db->query('SELECT id,id_request,no_st,d_st, pjb_ttd_st, kategori_tugas, perihal_tugas,lokasi_tugas,dt_berangkat,dt_kembali,transportasi,allowance FROM '.$this->data_source.' WHERE `'.key($record).'` > '.$this->db->escape(current($record)).' ORDER BY `'.key($record).'` ASC LIMIT 1')->result_array());
		$data['last'] = current($this->db->query('SELECT id,id_request,no_st,d_st, pjb_ttd_st, kategori_tugas, perihal_tugas,lokasi_tugas,dt_berangkat,dt_kembali,transportasi,allowance FROM '.$this->data_source.' ORDER BY `'.key($record).'` DESC LIMIT 1')->result_array());
		$result		= compact('metadata', 'data');
		return $result;
	}
	function select_query($var_select=NULL,$var_where=NULL,$order_by=NULL) //select, where in format array or string 'cond="value"' order by one value
		{
			if($var_select != NULL){
				if (is_array($val_select))
				{
					$this->db->select(implode(',',$field));
				}else{
					if(!$var_select)
					{
						$this->db->select($var_select);
					}
				}
			}

			if($var_where != NULL)
			{
				if (is_array($var_where)){
					foreach($var_where as $key=>$val){
						$this->db->where($key,$val);
					}
				}else{
					$this->db->where("`".substr($var_where,0,strpos($var_where,"="))."`",substr($var_where,strpos($var_where,"=")+1));
				}
			}

			if($order_by != NULL){
				$this->db->order_by($order_by);
			}

			$query = $this->db->get($this->data_source);
			return $query->result();
		}
}

?>
